<?php
require_once $GLOBALS['ROO'] . 'Modules/Operative/class.operative.php';
require_once $GLOBALS['ROO'] . 'Libraries/Pr_db/Transaction/transact.class.php';

function haveResult($result) {
    if ($result[0] > 0) {
        return true;
    } else {
        return false;
    }
}

function metodoDePagamentoDefinido($result) {
    if (isset($result)) {
        return true;
    } else {
        return false;
    }
}

$SelectedPayOrders = substr($_POST['POOL'], 0, strlen($_POST['POOL']) - 1);
if ($SelectedPayOrders == '') {
    $Msg_ERROR = "Não foi indicada nenhuma ordem de pagamento.";
}
$TransmissionResultCode = 1;

if (isset($Msg_ERROR)) {
    echo $Msg_ERROR;
    die;
}

$GET_OrdersToProcess = $GLOBALS['MYT']->db_array("SELECT
  GROUP_CONCAT(Op_Orden SEPARATOR ',') AS SelectedPayOrders,
  Op_Corr,
  Op_Modo,
  Op_MonCobro,
  Op_MonDPago
  FROM ordenespago
  WHERE Op_Orden IN ({$SelectedPayOrders})
  AND (Op_Enviada = 0 AND Op_Modo = 2 OR Op_Enviada = 0 AND Op_Modo = 1)
  GROUP BY Op_Corr, Op_Modo");

$CGET = $GET_OrdersToProcess[0];

if (!haveResult($GET_OrdersToProcess)) {
    echo '<script charset="utf-8" type="text/javascript">alert("Não foi indicada nenhuma ordem de pagamento.");</script>';
    die;
}
for ($i = 1; $i <= $CGET; $i++) {
    $doPayment = new Operative();
    $doPayment->Operative_ValidatePayOrder($GET_OrdersToProcess[$i]);
    unset($doPayment);
}
include($GLOBALS['PAD'] . 'Modules/FTK9D4D0/Lib/a05_elem_trans.mex');
?>
<script charset="utf-8" type="text/javascript">
    document.QueryPayOrders.action='Modules/FTK9D4D0/Lib/a05_gestpayorder.mex';
    subform('QueryPayOrders','ConsolePay');
</script>
